package com.dhcc.core.modules.system.service.impl;

import java.io.Serializable;
import java.util.List;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.dhcc.core.framework.base.service.impl.BaseServiceImpl;
import com.dhcc.core.framework.result.node.ZTreeNode;
import com.dhcc.core.modules.system.dao.GroupMapper;
import com.dhcc.core.modules.system.entity.Group;
import com.dhcc.core.modules.system.service.IGroupService;
/**
 * 群组表数据服务层接口
 * 
 * @ClassName: GroupServiceImpl
 * @Description: TODO
 * @author lifan
 * @date 2018-08-21 10:11:02
 */
@Service("groupService")
public class GroupServiceImpl extends BaseServiceImpl<GroupMapper, Group> implements IGroupService {
	
	@Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteById(Serializable id,Long groupId) {
		this.baseMapper.deleteGroupMemberById(groupId);
        return retBool(baseMapper.deleteById(id));
    }
	
	@Override
	public List<ZTreeNode> groupTree(String map) {
		String[] params =map.split(",");
		int isPublic=Integer.parseInt(params[0]);
		if(isPublic==1){
			return this.baseMapper.tree(isPublic,null);
		}
		else{
	        Long userId=Long.parseLong(params[1]);
			return this.baseMapper.tree(isPublic,userId);
		}
	}

    @Override
    public List<ZTreeNode> treeMemberPublic() {
        List<ZTreeNode> tree = this.baseMapper.treeMember(1, null);
        ZTreeNode root = ZTreeNode.createRoot();
        root.setName("公共群组");
        root.setIsParent(true);
        root.setIsOpen(true);
        tree.add(root);
        return tree;
    }

    @Override
    public List<ZTreeNode> treeMemberPersonal(Long userId) {
        List<ZTreeNode> tree = this.baseMapper.treeMember(0, userId);
        ZTreeNode root = ZTreeNode.createRoot();
        root.setName("个人群组");
        root.setIsParent(true);
        root.setIsOpen(true);
        tree.add(root);
        return tree;
    }
	
}